{% extends 'AdminPanelDashboardBundle::layout.html.twig' %}


{% block stylesheets %}
  {{ parent() }}
{% endblock %}

{% block javascripts %}
{{ parent() }}
<!-- jQuery Validate -->
<script src="/adminTemplate/theme/scripts/jquery-validation/dist/jquery.validate.min.js" type="text/javascript"></script>
<script src="/adminTemplate/theme/scripts/form_validator.js" type="text/javascript"></script>
<script>

$( document ).ready(function() {
  
  callRadioClick();
  
});

function callRadioClick()
{
  $(".is_correct").click(function(){
    $(this).val($(this).prev().val());    
  })
  
}

function addQuestion()
{
  var lineNUmber = parseInt($("#lineNumber").val());
  lineNUmber = lineNUmber + 1;  
  $(".questionContainer:last").after('<div class="control-group questionContainer" id="questionContainer_'+lineNUmber+'"><label class="control-label"><a href="javascript:;" onclick="removeLine('+lineNUmber+')">Хасах</a></label><div class="controls"><textarea class="answers" name="answers[]" /><input type="radio" name="is_correct" class="is_correct" value=""></input></div></div>');
  $("#lineNumber").val(lineNUmber);
  callRadioClick();
}

function removeLine(chosenLine)
{
  $("#questionContainer_"+chosenLine).remove();
  var lineNUmber = parseInt($("#lineNumber").val());
  lineNUmber = lineNUmber - 1;
  $("#lineNumber").val(lineNUmber);
}

  </script>
  
{% endblock %}

{% block content %}

<div id="content">
  <ul class="breadcrumb">
    <li><a href="index.php" class="glyphicons home"><i></i> Нүүр</a></li>
    <li class="divider"></li>
    <li><a href="{{path('admin_question')}}">Асуулт</a></li>
  </ul>
  <div class="separator"></div>

  <h3 class="glyphicons show_thumbnails_with_lines"><i></i> Шалгалт</h3>
  <div class="separator"></div>

  <form class="form-horizontal" style="margin-bottom: 0;" id="contentEditForm" action="{{ path('admin_question_create') }}" method="post" {{ form_enctype(form) }} autocomplete="off">

    <div class="well" style="padding-bottom: 20px; margin: 0;">
      <h4>Шалгалтын асуулт шинээр нэмэх</h4>
      <hr class="separator" />
      <div class="row-fluid">
        <div class="span6" style="width: 90%">                    

            <div class="control-group">  
              <div class="widget-body" style="padding: 10px 0 0;">              
              {{ form_label(form.question, label|default(null), { 'label_attr': { 'class': 'control-label' } }) }}
              <div class="controls">{{ form_widget(form.question, { 'attr': {'class': 'wysihtml5 span12', 'rows' : '5'} }) }}</div>              
              </div>
            </div>
          
            <div class="control-group">                
                {{ form_label(form.isActive, label|default(null), { 'label_attr': { 'class': 'control-label' } }) }}
              <div class="controls">{{ form_widget(form.isActive, { 'attr': {'class': 'span12'} }) }}</div>
            </div>

            
            <hr class="separator" />
            
            <div class="control-group">                
              <label class="control-label"><h4 style="width: 120px;">Хариулт </h4></label>
              <div class="controls"><a href="javascript:;" onclick="addQuestion()">Нэмэх</a><input type="hidden" value="1" id="lineNumber" name="lineNumber"/></div>
            </div>
            <div class="control-group questionContainer" id="questionContainer_1">                
              <label class="control-label"></label>
              <div class="controls"><textarea name="answers[]" class="answers"></textarea><input type="radio" name="is_correct" class="is_correct" value=""></input></div>
            </div>
            <div class="form-actions">
              <button type="submit" class="btn btn-icon btn-primary glyphicons circle_ok"><i></i>Хадгалах</button>
              <a href="{{ path('admin_question') }}"><button type="button" class="btn btn-icon btn-default glyphicons circle_remove"><i></i>Буцах</button></a>
            </div>
          </div>
{{ form_widget(form._token) }}
          </form>
          <!-- End Content -->
        </div>

{% endblock %}
